import digits
import webbrowser
from server import run_server
import subprocess


LOGIN_URL = 'http://202.194.116.116/srun_portal_pc?ac_id=5&theme=basic1'


def prepare():
    digits.countdown5()
    webbrowser.open(LOGIN_URL)


def is_online():
    # url = 'https://www.baidu.com'
    cmd = 'ping baidu.com -n 1'
    
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    proc.communicate()
    return proc.returncode == 0


if __name__ == '__main__':
    print('检查是否联网...', end='')
    if is_online():
        print('已经连，无需操作')
        quit()
    print('未连，准备连接')
    prepare()
    run_server()
